﻿using AuthCenter_Comons;
using AuthCenter_HuangJingtao.Domain;
using AuthCenter_HuangJingtao.ErrorCode;
using AuthCenter_HuangJingtao.Read.Api.Application.Command.AppaLL;
using AuthCenter_HuangJingtao.Read.Api.Application.CommandHandler;
using AuthCenter_HuangJingtao.Read.Api.Dto;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace AuthCenter_HuangJingtao.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class AppsAllController : ControllerBase
    {
        IMediator mediator;
        public AppsAllController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        [HttpPost]
        public async Task<ApiResult<int>> AddApp(App Apps)
        {
            try
            {
                AddAppCommand AddAppCommand = new AddAppCommand()
                {
                    Apps = Apps
                };
                return await mediator.Send(AddAppCommand);
            }
            catch (Exception)
            {
                throw;
            }
        }

        [HttpPost]
        public async Task<ApiResult<int>> UpdateApp(App Apps)
        {
            try
            {
                UpdateCommand UpdateCommand = new UpdateCommand()
                {
                    Apps = Apps
                };
                return await mediator.Send(UpdateCommand);
            }
            catch (Exception)
            {
                throw;
            }
        }

        [HttpGet]
        public async Task<ApiResult<List<ShowDto>>> ShowApp()
        {
            try
            {
                ShowCommand ShowCommand = new ShowCommand();
                return await mediator.Send(ShowCommand);
            }
            catch (Exception)
            {
                throw;
            }
        }

        [HttpGet]
        public async Task<ApiResult<List<Addresses>>> ShowAdrrss()
        {
            try
            {
                ShowAddressCommand ShowAddressCommand = new ShowAddressCommand();
                return await mediator.Send(ShowAddressCommand);
            }
            catch (Exception)
            {
                throw;
            }
        }

        [HttpGet]
        public async Task<ApiResult<List<Citys>>> ShowCit(int Addrss_Id)
        {
            try
            {
                ShowCitryCommand ShowCitryCommand = new ShowCitryCommand()
                {
                    Addrss_Id = Addrss_Id
                };
                return await mediator.Send(ShowCitryCommand);
            }
            catch (Exception)
            {
                throw;
            }

        }
        [HttpDelete]
        public async Task<ApiResult<int>> DelApp(int id)
        {
            try
            {
                DelCommand DelCommand = new DelCommand()
                {
                    id = id
                };
                return await mediator.Send(DelCommand);
            }
            catch (Exception)
            {
                throw;
            }
        }

        [HttpGet]
        public async Task<ApiResult<List<Xians>>> ShowXian(int CityId)
        {
            try
            {
                ShowXianCommand ShowXianCommand = new ShowXianCommand()
                {
                    CityId = CityId
                };
                return await mediator.Send(ShowXianCommand);
            }
            catch (Exception)
            {
                throw;
            }
        }

        [HttpGet]
        public async Task<ApiResult<App>> FirstAppShow(int id)
        {
            try
            {
                FirstAppShowCommand FirstAppShowCommand = new FirstAppShowCommand()
                {
                    id = id
                };
                return await mediator.Send(FirstAppShowCommand);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
